home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / utility / whelp.zip / WHELP.C < prev    next >
C/C++ Source or Header  |  1992-06-03  |  3KB  |  138 lines

  1. /****************************************************************/
  2. /*                                */
  3. /*    whelp.c                            */
  4. /*                                */
  5. /*    A command line interface for winhelp            */
  6. /*                                */
  7. /*    Created 1-6-92 M.Dobie                    */
  8. /*                                */
  9. /****************************************************************/
  10.  
  11. /*
  12.     Copyright
  13.     ---------
  14.  
  15.     whelp is copyright 1992 by Mark Dobie
  16.  
  17.     Permission to use, copy, modify, distribute, and sell this software
  18.     and its documentation for any purpose is hereby granted without fee,
  19.     provided that the above copyright notice appear in all copies and
  20.     that both that copyright notice and this permission notice appear
  21.     in supporting documentation.
  22. */
  23.  
  24. #define    STRICT
  25.  
  26. #include    <windows.h>
  27. #include    <stdlib.h>
  28. #include    <stdio.h>
  29. #include    <string.h>
  30.  
  31. /****************************************************************/
  32.  
  33. /*
  34.     win_error
  35.  
  36.     Display an error message on the screen...
  37. */
  38.  
  39. void    win_error(char far *message)
  40. {
  41.     MessageBeep(MB_ICONHAND) ;
  42.     MessageBox((HWND)NULL, message, "Program Error",
  43.            MB_ICONHAND | MB_OK | MB_TASKMODAL) ;
  44. }
  45.  
  46. /****************************************************************/
  47.  
  48. /*
  49.     Command line processing.
  50.  
  51.     whelp [-f helpfile] topic
  52.  
  53.  -    cmd_line is the command line to process
  54.  -    help_file will be set to the help file to look at
  55.     "" => none specified
  56.  -    help_topic is the topic to look up
  57.     "" => none specified
  58. */
  59.  
  60. static    void    process_command_line(char far *cmd_line,
  61.                      char far *help_file,
  62.                      char far *help_topic)
  63. {
  64.     char far    *token ;
  65.     int        got_helpfile ;
  66.  
  67.     token = strtok(cmd_line, " ") ;
  68.     if (token == NULL)
  69.     {
  70.         *help_file = *help_topic = '\0' ;
  71.         return ;
  72.     }
  73.  
  74.     got_helpfile = FALSE ;
  75.  
  76.     /* Is it the helpfile option? */
  77.     if (((*token     == '-') || (*token     == '/')) &&
  78.         ((*(token+1) == 'f') || (*(token+1) == 'F')))
  79.         got_helpfile = TRUE ;
  80.  
  81.     if (got_helpfile)
  82.     {
  83.         /* Get the help file name */
  84.         token = strtok(NULL, " ") ;
  85.         if (token == NULL)
  86.             *help_file = '\0' ;
  87.         else
  88.             strcpy(help_file, token) ;
  89.  
  90.         /* Get the help topic name */
  91.         token = strtok(NULL, " ") ;
  92.         if (token == NULL)
  93.             *help_topic = '\0' ;
  94.         else
  95.             strcpy(help_topic, token) ;
  96.     }
  97.     else
  98.     {
  99.         *help_file = '\0' ;
  100.         strcpy(help_topic, token) ;
  101.     }
  102.     return ;
  103. }
  104.  
  105. /****************************************************************/
  106.  
  107. /*
  108.     This is like main.
  109. */
  110.  
  111. int    PASCAL    WinMain(HINSTANCE instance, HINSTANCE prev_instance,
  112.                     LPSTR cmd_param, int cmd_show)
  113. {
  114.     char    help_file[BUFSIZ] ;
  115.     char    help_topic[BUFSIZ] ;
  116.  
  117.     process_command_line(cmd_param, help_file, help_topic) ;
  118.  
  119.     /* Usage message */
  120.     if ((*help_topic == '\0') && (*help_file == '\0'))
  121.     {
  122.         win_error("usage : whelp [/F helpfile] topic") ;
  123.         exit(1) ;
  124.     }
  125.  
  126.     /* What is the help file? */
  127.     if (*help_file == '\0')
  128.         strcpy(help_file, "win31wh.hlp") ;
  129.  
  130.     /* Try to invoke winhelp with the topic */
  131.     WinHelp(GetDesktopWindow(),
  132.         help_file,
  133.         HELP_PARTIALKEY,
  134.         (DWORD)(char far *)help_topic) ;
  135.  
  136.     return(0) ;
  137. }
  138.